/**
 * 版权所有 2009-2015 旺晓杨 peonyxy@msn.cn
 **/
package com.cn;

import java.util.ArrayList;
import java.util.List;

import org.htmlparser.Node;
import org.htmlparser.NodeFilter;
import org.htmlparser.Parser;
import org.htmlparser.filters.NodeClassFilter;
import org.htmlparser.filters.OrFilter;
import org.htmlparser.tags.FrameTag;
import org.htmlparser.tags.ImageTag;
import org.htmlparser.tags.LinkTag;
import org.htmlparser.tags.ObjectTag;
import org.htmlparser.util.NodeList;


public class Image  {

	public void test(){
		//http://www.w3schools.com/flash/tryit.asp?filename=tryhtml_ball
		String url = "http://flash.jninfo.net/showflash.asp?id=2562";
	
		List link = new ArrayList();
		
		List image = new ArrayList();
		List flash = new ArrayList();
		this.swoop(url,link,image,flash);
	}
	
	/**
	 * ��ù��˽ڵ���Ϣ
	 * @param url
	 * @param link
	 * @param image
	 * @param flash
	 */
	public void swoop(String url,List link,List image,List flash){
		try {
			NodeFilter filter = new NodeClassFilter(LinkTag.class);
			NodeFilter filterImage = new NodeClassFilter(ImageTag.class); 
		
			NodeFilter filterframeTag = new NodeClassFilter(FrameTag.class); 
			NodeFilter objectFilter = new NodeClassFilter(ObjectTag.class);
			
			Parser parser = new Parser();
			parser.setURL(url);
			parser.setEncoding(parser.getEncoding());
			
			OrFilter lastFilter = new OrFilter();
			lastFilter.setPredicates(new NodeFilter[] { filter,
					filterImage,filterframeTag,objectFilter});
//			NodeList list = parser.extractAllNodesThatMatch(filter);
			NodeList list = parser.parse(lastFilter);

			for (int i = 0; i < list.size(); i++) {
				Node node =  list.elementAt(i);
				if(node instanceof LinkTag ){
					LinkTag linkTag = (LinkTag) node;
					link.add(linkTag.extractLink());
					//System.out.println("testLinkTag() Link is :" + linkTag.extractLink());
				}
				else if(node instanceof ImageTag){
					ImageTag imageTag = (ImageTag) node;
					image.add(imageTag.getImageURL());
					System.out.println("ImageTag() Image  :" + imageTag.getImageURL());
				}
				
				else if(node instanceof FrameTag){
					FrameTag frameTag = (FrameTag) node;
					System.out.println("frameTag() frameTag :" + frameTag.getFrameLocation());
				}else if (node instanceof ObjectTag)
				{
					ObjectTag objectnode = (ObjectTag) node;
//					String mwvname = objectnode.getParameter("filename");//����WMV��ʽ��
					String flashname = objectnode.getParameter("movie");//����FLASH
					flash.add(flashname);
//					String shockwave = objectnode.getParameter("src");//����Shockwave��RM��ʽ��
//					if(mwvname!=null) System.out.println("======1====:"+mwvname);
					if(flashname!=null)  System.out.println("====2======:"+flashname);
//					if(shockwave!=null)  System.out.println("====3======:"+shockwave);

				}
				
			}
			} catch (Exception e) {
			e.printStackTrace();
			System.out.println("ץȡ����");
			}
	} 
}